<template>
  <div class="upload-container">
    <a-card class="upload-card">
      <h1>PDF智能解读助手</h1>
      <a-tabs default-active-key="1">
        <a-tab-pane key="1" tab="本地上传">
          <a-upload-dragger
            :before-upload="handleBeforeUpload"
            :show-upload-list="false"
            accept=".pdf"
          >
            <p class="ant-upload-drag-icon">
              <a-icon type="inbox" />
            </p>
            <p class="ant-upload-text">点击或拖拽PDF文件到此区域上传</p>
            <p class="ant-upload-hint">支持单个文件上传，文件大小不超过50MB</p>
          </a-upload-dragger>
        </a-tab-pane>
        <a-tab-pane key="2" tab="URL上传">
          <a-form-item>
            <a-input-search
              v-model="pdfUrl"
              placeholder="请输入PDF文件URL"
              enter-button="上传"
              @search="handleUrlUpload"
            />
          </a-form-item>
        </a-tab-pane>
      </a-tabs>
    </a-card>
  </div>
</template>

<script>
export default {
  name: "UploadPage",
  data() {
    return {
      pdfUrl: "",
    };
  },
  methods: {
    handleBeforeUpload(file) {
      const isLt50M = file.size / 1024 / 1024 < 50;
      if (!isLt50M) {
        this.$message.error("文件大小不能超过50MB!");
        return false;
      }
      this.$store.dispatch("uploadPdf", file);
      return false;
    },
    handleUrlUpload(url) {
      if (!url) {
        this.$message.error("请输入有效的URL地址");
        return;
      }
      // TODO: 验证URL格式
      this.$store.dispatch("uploadPdf", { url });
    },
  },
};
</script>

<style scoped>
.upload-container {
  height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
  background-color: #f0f2f5;
}

.upload-card {
  width: 600px;
  text-align: center;
}

.upload-card h1 {
  margin-bottom: 24px;
  color: rgba(0, 0, 0, 0.85);
}

.ant-upload-drag-icon {
  margin-bottom: 16px;
}

.ant-upload-text {
  margin-bottom: 8px;
  color: rgba(0, 0, 0, 0.85);
}
</style>
